<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../../connection/connection.php';
include "../../value/value_kr.php";
$monitor = $_REQUEST['monitor'];
$monitorname=$_REQUEST['monitorname'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=edge" />
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<link href="../../popup-window.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../popup-window.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	ScrollTable();
	
});
function MyResize(){
	ScrollTable();
}

function ScrollTable(){
	wid = $("table#tablebody2").parent().css('width');
	wid = wid.slice(0,-2)-17;
	$("table#tablebody2").css("width", wid);
	$("table#tablebodyheader").css("width", wid);
	$('table#tablebody2').parent().scrollTop(0);
	OnTRCSS();
}
function OnTRCSS(){
	$("table.tbchung tr:even").each(function(){
		$(this).css("background-color","#eff3fa");
	});
}
</script>
<script type="text/javascript">
$(function() {
	 var checkexistus = '<?=$_SESSION['iduser']?>';
	if(checkexistus==''){
		admin_logout();
		}
});

function onclickRowPC(els,idrowpc){
	$('#tablebody2 tr.select').removeClass('select');
	$(els).addClass('select');
	
	document.getElementById('idrowpc').value=idrowpc;
	document.getElementById('idhiddenRowPC').value=idrowpc;
	//alert('page- ' + page);
	$.ajax({url:"detail-pc.php?idrowpc="+idrowpc,success:function(result){
		document.getElementById('iddetailtable').innerHTML=result;
		document.getElementById('buttonAdd').setAttribute("class","inbtnDisable");
		document.getElementById('buttonAdd').className = "inbtnDisable";
		
		document.getElementById('buttonEdit').setAttribute("class","inbtn");
		document.getElementById('buttonEdit').className = "inbtn";
		
		document.getElementById('buttonDelete').setAttribute("class","inbtn");
		document.getElementById('buttonDelete').className = "inbtn";
		
		document.getElementById('buttonEdit').disabled = false;
		document.getElementById('buttonDelete').disabled = false;

		document.getElementById('ippc').style.backgroundColor = "#CCCCCC";
		$('#ippc').attr('readonly',true);
		}
	});
}
function addPC(){
	var ippc = $('#ippc').val();
	var namepc = $('#namepc').val();
	var totalhardisk = $('#totalhardisk').val();
	var usedhardisk = $('#usedhardisk').val();
	if(ippc.length==0){
		alert('ip pc is not null');
		return false;
	}
	if(Number(totalhardisk)<Number(usedhardisk)){
		alert('total hard disk value must larger than used hard disk');
		return false;
	}
	$.ajax({url:"check-exist-pc.php?ippc="+ippc,success:function(result){
		
		document.getElementById('dvidpchidden').innerHTML = result;
		var results = document.getElementById('idpchidden').value;
			if(results=='no'){
		   		alert('ip pc already existed');
		   		return false;
	   		}else{
	   			var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	   			$.ajax({url:"addPC.php?ippc="+ ippc+"&namepc="+namepc+"&totalhardisk="+totalhardisk+"&usedhardisk="+usedhardisk+"&winH="+winH,success:function(result){
	   				document.getElementById('tablecontentPC').innerHTML=result;
	   				ScrollTable();
	   				alert('insert successfully');
	   				resetPC();
	   				}
	   			});
	   		}
		}
	});
	
	
}
function editPC(){
	var idpc = document.getElementById('idhiddenRowPC').value;
	var namepc = document.getElementById('namepc').value;
	var totalhardisk = document.getElementById('totalhardisk').value;
	var usedhardisk = document.getElementById('usedhardisk').value;
	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	
	if(Number(totalhardisk)<Number(usedhardisk)){
		alert('total hard disk value must larger than used hard disk');
		return false;
	}
	//alert('page = '+page);
	$.ajax({url:"editPC.php?idpc="+ idpc+"&namepc="+namepc+"&totalhardisk="+totalhardisk+"&usedhardisk="+usedhardisk+"&winH="+winH,success:function(result){
		document.getElementById('tablecontentPC').innerHTML=result;
		ScrollTable();
		alert('edit successfully');
		resetPC();
		}
	});
}
function deletePC(){
	var idpc = document.getElementById('idhiddenRowPC').value;

	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	
	$.ajax({url:"deletePC.php?idpc="+idpc+"&winH="+winH,success:function(result){
		document.getElementById('tablecontentPC').innerHTML=result;
		ScrollTable();
		alert('delete successfully');
		resetPC();
		}
	});
}
function resetPC(){
	$("#ippc").removeAttr('readonly');
	document.getElementById('ippc').style.backgroundColor ="#ffffff";
	
	document.getElementById('nameSearch').value="";
	document.getElementById('ippc').value="";
	document.getElementById('namepc').value="";
	document.getElementById('totalhardisk').value="";
	document.getElementById('usedhardisk').value="";

	document.getElementById('buttonEdit').setAttribute("class","inbtnDisable");
	document.getElementById('buttonEdit').className = "inbtnDisable";
	
	document.getElementById('buttonDelete').setAttribute("class","inbtnDisable");
	document.getElementById('buttonDelete').className = "inbtnDisable";
	
	document.getElementById('buttonEdit').disabled = true;
	document.getElementById('buttonDelete').disabled = true;
	document.getElementById('buttonAdd').setAttribute("class","inbtn");
	document.getElementById('buttonAdd').className = "inbtn";
	
	document.getElementById('buttonAdd').disabled = false;
}
function searchAllPC(){
	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	
	$.ajax({url:"searchAllPC.php?winH="+winH,success:function(result){
		document.getElementById('nameSearch').value="";
		document.getElementById('tablecontentPC').innerHTML = result;
		ScrollTable();
		}
	});
}
function sortAndPagingPC(string,flagDesc){
	var search = document.getElementById('nameSearch').value ;
	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	
	$.ajax({url:"sortAndPagingPC.php?string="+string+"&flagDesc="+flagDesc+"&search="+search+"&winH="+winH,success:function(result){
		var expr = new RegExp('>[ \t\r\n\v\f]*<', 'g');
		var response_html_fixed = result.replace(expr, '><');
		
		document.getElementById('tablecontentPC').innerHTML = response_html_fixed;
		ScrollTable();
			}
	});
}

function admin_logout(){
	window.location="../../view_logout.php?changepage=admin";
}
function onclickSearch(){
	window.location = "../../search/searchcarnums.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>";
}
function onclickView(){
	window.location = "../../index.php?viewaction=none";
}
function loadpos(){
	var winHf = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	$("#divscroll").css("height", parseInt(winHf - 280));
}

function ajaxLoadContentPC(){
	var winH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	$.ajax({url:"ajax_content_PC.php?winH="+winH,success:function(result){
		document.getElementById('tablecontentPC').innerHTML = result;
		ScrollTable();
		}
	});
}
</script>
</head>
<?php 
$sql = "SELECT p.* FROM pc p";
?>
<?php include 'show_function_popup_carcrime.php';?>
<body onresize="MyResize();" onload="loadpos();ajaxLoadContentPC();load_popup_carCrime();">
<p id="maylya" ><input type="hidden"  id="mayly" name="mayly" /></p>
<div id="dvidpchidden" style="display: none;"><input type="hidden" id="idpchidden"></div>
    <div id="menu" style="text-align: center;">
    	<ul class="amenu">
        	<li><a onclick="onclickSearch();"><input class="csssearch" type="button"/></a></li>
            <li style="background:#1e7bbd"><a href=""><input class="cssadminchoose" type="button"/></a></li>
            <li style="width: 215px;"><a onclick="onclickView();"><input class="cssview" type="button"/></a>
	            <select class="seltopadmin" disabled="disabled">
	            		<option><?php echo $monitorname;?></option>
	            </select>
            </li>
            <li><a onclick="admin_logout()" style="cursor:pointer" ><input class="csslogout" type="button"/></a></li>
        </ul>
         <div class="clear"></div>
    </div>
    <div id="submenu">
    	<ul class="asubmenu">
        	<li><a href="../content-monitor-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_monitor?></a></li>
            <li><a href="../camera/content-camera-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_camera?></a></li>
           <li><a href="../car-crime-input-by-user/car-crime-input-by-user-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_carcrimeuser?></a></li>
            <li><a href="../car-crime/content-car-crime-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>"><?php echo $l_carcrime?></a></li>
            <li><a href="#" style="background:#034776; border-radius:6px">PC</a></li>
            <li><a href="../user/content-user-admin.php?monitor=<?=$monitor?>&monitorname=<?=$monitorname?>" ><?php echo $l_user?></a></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="main">
   	 	<table cellpadding="0" cellspacing="0" border="0"  class="tbm1" style="margin-bottom:10px">
        	<tr>
            	<td><?php echo $l_name?></td>
                <td colspan="9"><input type="text" class="intext" style="width:100px;padding-left: 5px;line-height: 26px;text-align: left;" id="nameSearch" name="nameSearch"/>  
                <input type="button" class="inbtn" style="width: 65px;"  value="<?php echo $l_search?>" onclick="sortAndPagingPC('p.name',1);" />  
                <input type="button" class="inbtn" style="width: 65px;"  value="All" onclick="searchAllPC();"/></td>
            </tr>
           </table>
           <div  id="iddetailtable">
            <table cellpadding="0" cellspacing="0" border="0" width="96%" class="tbm1" style="margin-bottom:10px">
	            <tr>
	                <td>IP</td>
	                <td><input type="text" class="intext" style="width:300px;padding-left: 5px;line-height: 26px;text-align: left;" id="ippc" name="ippc" /></td>
	                <td><?php echo $l_name?></td>
	                <td><input type="text" class="intext" style="width:300px;padding-left: 5px;line-height: 26px;text-align: left;" id="namepc" name="namepc"/></td>
	                <td><?php echo $l_totalhardisk?></td>
	                <td><input type="text" class="intext" style="width:200px;padding-left: 5px;line-height: 26px;text-align: left;" id="totalhardisk" name="totalhardisk"/></td>
	                <td><?php echo $l_usedhardisk?></td>
	                <td><input type="text" class="intext" style="width:200px;padding-left: 5px;line-height: 26px;text-align: left;" id="usedhardisk" name="usedhardisk"/></td>
	                <td><input type="button" class="inbtn" style="width: 65px;"  value="<?php echo $l_new?>" id="buttonAdd" onclick="addPC()"/></td>
	                <td><input type="button" class="inbtn" style="width: 65px;"  value="<?php echo $l_reset?>" onclick="resetPC();" /></td>
	            </tr>   
	            <tr>
	                <td colspan="8"></td>
	                <td><input type="button" class="inbtnDisable" style="width: 65px;"  value="<?php echo $l_edit?>" id="buttonEdit" onclick="editPC()" disabled="disabled"/></td>
	                <td><input type="button" class="inbtnDisable" style="width: 65px;"  value="<?php echo $l_delete?>" id="buttonDelete" disabled="disabled" 
	                onclick="if(confirm('<?=$l_areyousure?>')){ deletePC();return true;}else{return false;}"/></td>
	            </tr>   
      	  </table>
        </div>
        <div class="divtheader" style="min-width:624px;">
           	<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebodyheader">
        		<thead>
		            <tr>
		            	<th style="width: 5%">No</th>
		                <th style="width: 25%"><a onclick="sortAndPagingPC('p.ip',1)" style="cursor: pointer;color: #027acc">IP</a></th>
		                <th style="width: 30%"><a onclick="sortAndPagingPC('p.name',1)" style="cursor: pointer;color: #027acc"><?php echo $l_name?></a></th>
		                <th style="width: 20%"><a onclick="sortAndPagingPC('p.total_hardisk',1)" style="cursor: pointer;color: #027acc"><?php echo $l_totalhardisk?></a></th>
		                <th style="width: 20%;border-right: none !important;" class="last"><a onclick="sortAndPagingPC('p.used_hardisk',1)" style="cursor: pointer;color: #027acc"><?php echo $l_usedhardisk?></a></th>
		            </tr>
	            </thead>
           	</table>
        </div>
        <div id="tablecontentPC" style="width: 100%;">
        <div id="divscroll" style="overflow:scroll;overflow-x: hidden; width:100%; background-color: #ffffff">
	        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebody2">
	            <tbody>
	            
	            </tbody>              
	        </table>
	        </div>
	        </div>
    </div>
    <input type="hidden" id="idhiddenRowPC" name="idhiddenRowPC" value="">
        <?php include 'show_content_popup_carcrime.php';?>
</body>
</html>
 <?php mysql_close($connection);?>